import requests
import os
from tqdm import tqdm
from multiprocessing import Pool

def download(i):
    headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
    url = 'https://vouku.cdn7-okzv.com/20200227/17420/de316f66/1000k/hls/fc84cc6cd5800%04d.ts' % i
    response = requests.get(url, headers=headers)
    # os.makedirs('video', exist_ok=True)
    #
    # if response.status_code != 404:
    #     with open('./video/{}.ts'.format(i), 'wb') as f:
    #         f.write(response.content)
    # if i % 10 == 0:
    #     print('\r进度: {:.4}%'.format((i / 1850) * 100), end='')

def main():
    download(1)
    # pool = Pool(10)
    # for i in tqdm(range(1, 1851)):  # 修正范围到1851，因为range是左闭右开的
    #     pool.apply_async(download, args=(i,))
    # pool.close()
    # print(f"开始下载》》》》")
    # pool.join()
    # print(f"下载完成》》》》")

if __name__ == '__main__':
    main()
